//
//  ZTStringParser.m
//  ZHYYTool
//
//  Created by MT-SW-005 on 2021/11/8.
//  Copyright © 2021 MT-SW-005. All rights reserved.
//

#import "ZTStringParser.h"

@implementation ZTStringParser

/**
 去除字符串首尾的空格
 */
+(NSString*)trimSpace:(NSString*)aString
{
     NSString *trimString = [aString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
    return trimString;
}


/**
 + (NSCharacterSet *)controlCharacterSet;
 + (NSCharacterSet *)whitespaceCharacterSet;
 + (NSCharacterSet *)whitespaceAndNewlineCharacterSet;
 + (NSCharacterSet *)decimalDigitCharacterSet;
 + (NSCharacterSet *)letterCharacterSet;
 + (NSCharacterSet *)lowercaseLetterCharacterSet;
 + (NSCharacterSet *)uppercaseLetterCharacterSet;
 + (NSCharacterSet *)nonBaseCharacterSet;
 + (NSCharacterSet *)alphanumericCharacterSet;
 + (NSCharacterSet *)decomposableCharacterSet;
 + (NSCharacterSet *)illegalCharacterSet;
 + (NSCharacterSet *)punctuationCharacterSet;
 + (NSCharacterSet *)capitalizedLetterCharacterSet;
 + (NSCharacterSet *)symbolCharacterSet;
 + (NSCharacterSet *)newlineCharacterSet NS_AVAILABLE(10_5, 2_0);
 */
+(NSString*)trimString:(NSString*)aString withCharacterSet:(NSCharacterSet*)characterSet
{
    NSString *trimString = [aString stringByTrimmingCharactersInSet:characterSet];
    return trimString;
}

/**
 去除字符串首尾的:@／：；（）¥「」＂、[]{}#%-*+=_\\|~＜＞$€^•'@#$%^&*()_+'\"
 */
+(NSString*)trimString:(NSString*)aString
{
    NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"@／：；（）¥「」＂、[]{}#%-*+=_\\|~＜＞$€^•'@#$%^&*()_+'\""];
    NSString *trimString = [aString stringByTrimmingCharactersInSet:set];
    return trimString;
    
}



/*
 C语言字符串转化成OC字符串
 */
+(NSString*)charToString:(char*)cStr
{
    NSString *str = [NSString stringWithCString:cStr encoding:NSUTF8StringEncoding];
    return str;
       
}


/*
 OC语言字符串转化成C字符串
 */
+ (const char*)stringToChar:(NSString*)aString
{
    const char *cStr = [aString cStringUsingEncoding:NSUTF8StringEncoding];
    return cStr;
}

/*
从url中获取字符串
*/
+(NSString*)readStringFromURL:(NSString*)aurl
{
    NSURL *url = [NSURL URLWithString:aurl];
    NSString *string = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
    return string;
}

/*
从文件中获取字符串
*/
+(NSString*)readStringFromFile:(NSString*)filePath
{
    NSString *string = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:/*&error*/nil];
    return string;
}


/*
获取子串
*/
+(NSString*)subStringFromIndexToEnd:(NSString*)aString index:(NSInteger)anIndex
{
    NSString *string = [aString substringFromIndex:anIndex];
    return string;
}

/*
获取子串
*/
+(NSString*)subStringFromStartToIndex:(NSString*)aString index:(NSInteger)anIndex
{
     NSString *string = [aString substringToIndex:anIndex];
     return string;
}

/*
获取子串
*/
+(NSString*)subStringFromStart:(NSString*)aString  startIndex:(NSInteger)start length:(NSInteger)len
{
    NSString *string = [aString substringWithRange:NSMakeRange(start,len)];
    return string;
}

/*
 替换字符串
 */
+(NSString*)replaceString:(NSString*)aString  originString:(NSString*)anOriginString byString:(NSString*)replaceString
{
    NSString *string = [aString stringByReplacingOccurrencesOfString:anOriginString withString:replaceString];
    return string;
}


/*
分割字符串为数组
*/
+(NSArray *)separatString:(NSString*)aString byString:(NSString*)split{
     NSArray  *arr = [aString componentsSeparatedByString:split];
     return arr;
}

/*
把数组合并为字符串，通过分隔符合并
*/
+(NSString *)joinStringFormArray:(NSArray*)arr byString:(nullable NSString*)split{
    NSString *str;
    if (split ==nil) {
        str = [arr componentsJoinedByString:@""];
    }else{
        str = [arr componentsJoinedByString:split];
    }
    return str;
}

@end
